<template>
  <div>
    <def-layout type="col0-24" :page="page" @invoke="invoke">
      <div slot="search" class="form-items">
        <el-form-item>
          <el-input v-model="formSearch.keyword" placeholder="名称" />
        </el-form-item>
        <el-form-item>
          <el-input v-model="formSearch.no" placeholder="编码" />
        </el-form-item>
        <el-form-item>
          <el-select v-model="formSearch.used" placeholder="请选择状态">
            <el-option
              v-for="item in constants.generalUsed.values()"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
      </div>
      <div slot="content" class="grid">
        <page-grid v-if="self!=null" :parent="self">
          <div slot="columns">
            <el-table-column prop="no" align="center" label="编码" width="150" />
            <el-table-column prop="name" align="center" label="名称 " width="150" />
            <el-table-column prop="used" align="center" label="状态" width="100">
              <template slot-scope="scope">
                <column-filter v-model="scope.row.used" type="used" @click="filter" />
              </template>
            </el-table-column>
            <el-table-column prop="sort" align="center" label="排序" width="180" />
            <!-- <el-table-column prop="createTime" sortable align="center" label="创建时间" width="150" />
            <el-table-column prop="updateTime" sortable align="center" label="更新时间" width="150" /> -->
          </div>
        </page-grid>
      </div>
    </def-layout>
  </div>
</template>
<script>
import adminSupport from 'lola-admin-support-el'
export default {
  name: 'CostClass',
  components: {},
  mixins: [adminSupport.mixins.index],
  data() {
    return {
      name: 'CostClass',
      formSearch: { keyword: '', uesd: '' },
      self: null
    }
  },
  created() {
    this.init() // 页面自定义初始化
  },
  methods: {
    init() {
      var that = this
      that.loadData() // 加载数据(按钮+列表) 扩展需重写该方法
      this.self = that
    },
    search() {
      const queryList = []
      if (!String.isNullOrEmpty(this.formSearch.keyword)) {
        queryList.push({
          key: 'name',
          value: this.formSearch.keyword,
          oper: ':',
          join: 'and'
        })
      }
      if (!String.isNullOrEmpty(this.formSearch.no)) {
        queryList.push({
          key: 'no',
          value: this.formSearch.no,
          oper: ':',
          join: 'and'
        })
      }
      if (
        !String.isNullOrEmpty(this.formSearch.used) &&
        this.formSearch.used !== 'All'
      ) {
        queryList.push({
          key: 'used',
          value: this.formSearch.used,
          oper: '=',
          join: 'and'
        })
      }

      this.dataGrid.params.queryList = queryList
      this.refresh()
    },
    bindSearch() {
      this.formSearch = { keyword: '', used: '' }
    }

  }
}
</script>
